package com.zero.zui
{
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.Dictionary;
	
	import com.zero.zsingleton.ComponentSingleton;
	import com.zero.zutils.BaseUtils;
	import com.zero.zutils.UiUtils;
	
	public class ShapeTextButton extends Component
	{
		private static const Z_TEXT:String				= "Z_TEXT";
		private static const Z_TEXTFIELD:String			= "Z_TEXTFIELD";
		private static const Z_TEXT_POSITION:String 		= "Z_TEXT_POSITION";
		private static const Z_SHAPE_BUTTON:String		= "Z_SHAPE_BUTTON";
		
		private var _shapeButton		:ShapeButton;
		private var _textField			:ExtendTextField;
		private var _textStyle			:String;
		private var _text				:String;
		private var _textPosition		:String;
		private var _posPoint			:Point;
				
		public function ShapeTextButton()
		{
			super();
		}
		
		public function set textStyle($value:String):void
		{
			_textStyle = $value;
			_textField = ComponentSingleton.instance.createComponentByStylename($value);
			_textField.mouseEnabled = false;
			
			attributeChange(Z_TEXTFIELD);
		}
		
		public function get textField():TextField
		{
			return _textField;
		}
		
		public function set text($value:String):void
		{
			_text = $value;
			
			attributeChange(Z_TEXT);
		}
		
		public function set shapeButtonStyle($value:String):void
		{
			_shapeButton = ComponentSingleton.instance.createComponentByStylename($value);
			
			attributeChange(Z_SHAPE_BUTTON);
		}
		
		public function set textPosition($value:String):void
		{
			_posPoint = BaseUtils.stringToPoint($value);
			
			attributeChange(Z_TEXT_POSITION);
		}
		
		override public function attributeUpdate():void
		{
			if(_attributeDic[Z_SHAPE_BUTTON] && _attributeDic[Z_TEXTFIELD] && _attributeDic[Z_TEXT])
			{
				_textField.text = _text;
				_textField.x 	= _shapeButton.width/2 - _textField.width/2;
				_textField.y 	= _shapeButton.height/2 - _textField.height/2;
			}
			if(_attributeDic[Z_TEXT_POSITION])
			{
				_textField.x = _posPoint.x;
				_textField.y = _posPoint.y;
			}
		}
		
		override public function addChildren():void
		{
			UiUtils.addToDisplay(_shapeButton, this);
			UiUtils.addToDisplay(_textField, this);
		}
	}
}